import { useEffect, useState } from 'react'
import { getArticle } from '../../api/index';
import moment from 'moment';
function Article(props) {
    const { id } = props.match.params;
    const [article, setArticle] = useState({})
    useEffect(() => {
        async function init() {
            const { data } = await (getArticle(id))
            setArticle(data)
        }
        init()
    }, [id])
    const { title, author, create_time, content } = article;
    return <div style={{padding:20,backgroundColor:'white',marginTop:20,borderRadius:10}}>
        <h4>{title}
        </h4>
        <p>作者：{author}   时间：{moment(create_time).format('YYYY-MM-DD HH:mm')}</p>
        <p>
            {content}
        </p>
    </div>
}

export default Article